package com.sport.facilities.booking.system.httptask;

import java.util.List;

import android.content.Context;
import android.util.Log;

import com.sport.facilities.booking.system.htmlchecker.TransferBookingResultChecker;
import com.sport.facilities.booking.system.model.Booking;
import com.sport.facilities.booking.system.model.BookingRequestModel;

public class TransferBookingResultTask extends BasicTask {	
	
	private final String TAG = "TransferBookingResultTask";

	public TransferBookingResultTask(Context ctx, OnTaskCompleted completeAction) {
		super(ctx);
		this.listener = completeAction;
	}

	public void fnTransferBook(BookingRequestModel bkmodel) {
		try {
			super.onPreExecute();
			super.execute(PATH_POST_TRANSFER_BOOK,bkmodel);
		} catch (Exception e) {
			this.listener.onTaskFailed(e.getMessage());
		}
	}

	protected void onPostExecute(String result) {
		super.onPostExecute(result);
		Log.d(TAG, "onPostExecute");
		TransferBookingResultChecker tbChecker = new TransferBookingResultChecker();
		List<Booking> bookingList = null;
		try {
			bookingList = tbChecker.getTransferBookingFormfromHtml(result);
			this.listener.onTaskCompleted(bookingList);
		} catch (Exception e) {
			Log.e(TAG, "onPostExecuteException:" + e);
			this.listener.onTaskFailed(e.getMessage());
		}
	}

	public void setCompletedAction(OnTaskCompleted completeAction) {
		this.listener = completeAction;
	}
}
